function HandleTableBranchHistory(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  

  
  this._user = (options && options.user) ? options.user : null;
  this._date = (options && options.date) ? options.date : null;
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._noLog = (options && options.noLog) ? options.noLog : null;


  
  this._hpurchase = MiscUtils.find(options.produces, [{ attrs: ['parent_id'], value: this._item.id }]);
  
    //console.log(this._item);  
  this._createElements();
};

HandleTableBranchHistory.prototype._createElements = function() {
  var valid, track, a, model, state, _self = this;
  
  DOMUtils.removeTableRows(this._gui.main, 1);
  
  if (this._noLog) {
  if (this._hpurchase.length == 0) {
    tr = this._gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 8;
    td.style.height = '24px';
    td.style.backgroundColor = '#ebebe3';
    td.style.borderLeft = 'solid 1px #b4b4b4';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }

    this._gui.title.appendChild(document.createTextNode(this._item.name));
    MiscUtils.sort(this._hpurchase, ['operate_date']);
    
    //console.log(this._hpurchase);
    
    //console.log(this._item);


    
    
    for (var i = 0, il = this._hpurchase.length; i < il; i++) {
      var event = this._hpurchase[i];
      //console.log(event)
      var tr = this._gui.main.insertRow(-1);
       if(event.cancelled==1)
      {
         tr.style.textDecoration='line-through';
      }      

      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(SimpleDate.format(event.operate_date,1)));
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.user_account));

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.operate_action));
      
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(event.name));
        
    
    if (event.selects.length > 0) {
      a = document.createElement('a');
      a.style.fontSize = '10px';
      a.href = '#';
      a.appendChild(document.createTextNode('Info'));
      a._purchase = event;
      a.onclick = function() { var func1 = function() { _self._popupBox2._close(); };
                               var div = document.createElement('div');
                               MiscUtils.dialog(_self._popupBox2, DOMUtils.findPos(this), div, func1, null, {t: this._purchase.name, width: 520, height: 100});
                               new DialogDetails(div, this._purchase, { orderId: (_self._parent) ? _self._parent.id : null, purchases: _self._purchases, hidePrice: _self._options.hidePrice, pur: true });
                               return false;
                             };
      td.appendChild(a);
    }        
        
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.quantity));        

//      td = tr.insertCell(-1);
//     td.style.borderRight = 'solid 1px #b4b4b4';
//      td.style.borderBottom = 'solid 1px #b4b4b4';
//      td.style.height = '25px';
//      td.style.textAlign = 'left';
//      td.style.paddingLeft = '15px';
//      td.style.verticalAlign = 'middle';
//      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
//      td.appendChild(document.createTextNode(event.unit));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.price));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.total));  
      
    } 
    
    //当前产品信息
      var tr = this._gui.main.insertRow(-1);
      tr.style.color ='#ff0000';
      if(this._item.cancelled==1)
      {
         tr.style.textDecoration='line-through';
      }  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '35px';
      td.colSpan = '3';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(''));
      
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(this._item.name));
        
    if (this._item.selects.length > 0) {
      a = document.createElement('a');
      a.style.fontSize = '10px';
      a.href = '#';
      a.appendChild(document.createTextNode('Info'));
      a._purchase = this._item;
      a.onclick = function() { var func1 = function() { _self._popupBox2._close(); };
                               var div = document.createElement('div');
                               MiscUtils.dialog(_self._popupBox2, DOMUtils.findPos(this), div, func1, null, {t: this._purchase.name, width: 520, height: 100});
                               new DialogDetails(div, this._purchase, { orderId: (_self._parent) ? _self._parent.id : null, purchases: _self._purchases, hidePrice: _self._options.hidePrice, pur: true });
                               return false;
                             };
      td.appendChild(a);
    }        
        
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(this._item.quantity));        

 //     td = tr.insertCell(-1);
//      td.style.borderRight = 'solid 1px #b4b4b4';
//      td.style.borderBottom = 'solid 1px #b4b4b4';
//      td.style.height = '25px';
//      td.style.textAlign = 'left';
//      td.style.paddingLeft = '15px';
//      td.style.verticalAlign = 'middle';
//      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
//      td.appendChild(document.createTextNode(this._item.unit));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(this._item.price));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(this._item.total));         
    
    
    
    
  } else {
    this._gui.title.appendChild(document.createTextNode('Order Info'));
    MiscUtils.sort(this._hpurchase, ['operate_date']);
    
    //console.log(this._hpurchase);
    //console.log(this._item);
    for (var i = 0, il = this._hpurchase.length; i < il; i++) {
      var event = this._hpurchase[i];
      //console.log(event);
      

      var tr = this._gui.main.insertRow(-1);

      if(event.cancelled==1)
      {
         tr.style.textDecoration='line-through';
      }
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(SimpleDate.format(event.operate_date,1)));
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.user_account));

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.operate_action));
      
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(event.flag));
               
        
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.price));        

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.photoname));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.videoname));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(SimpleDate.format(event.date)));  
      
    } 
    
    //当前产品信息
      var tr = this._gui.main.insertRow(-1);
      tr.style.color ='#ff0000';
      if(this._item.cancelled==1)
      {
         tr.style.textDecoration='line-through';
      } 

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '35px';
      td.colSpan = '3';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(''));
      
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(this._item.flag));
        
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(this._item.price));        

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(this._item.photoname));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(this._item.videoname));  

      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(SimpleDate.format(this._item.date)));      
  }
};